#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: api08_worker.py 
@version:
@time: 2022/05/05 
"""
from TapClientCore.T02_tm_api.v2_api.v2_api_base import *


class Api08WorkerUrl(V2ApiUrlBase):
    url_worker = api_joint(V2ApiUrlBase().server, WORKERS)


class Api08Worker(V2ApiBase):
    def get_worker_by_filter(self):
        """
        通过filter 获取worker信息
        """
        response = self.tapclient(
            self.get,
            Api08WorkerUrl.url_worker
            + self.access_token
            + self.filter({
                "order": "ping_time DESC",
                "limit": 1,
                "fields": {
                    "worker_status": True
                },
                "where": {
                    "worker_type": "api-server",
                    "ping_time": {
                        "gte": "$serverDate",
                        "gte_offset": 30000
                    }
                }
            })
        )
        return response
